<?php

/**
 * Subclass for performing query and update operations on the 'topics' table.
 *
 *
 *
 * @package lib.model
 */
class TopicsPeer extends BaseTopicsPeer
{
    static public function getPager($perpage, $page, $parameters)
    {
        $c = new Criteria();

        $c = self::getSearchTopicsFromParam($c, $parameters);

        $c->addDescendingOrderByColumn(self::CREATED_AT);
        $pager = new sfPropelPager('Topics', $perpage);
        $pager->setCriteria($c);
        $pager->setPage($page);
        $pager->init();
        return $pager;
    }

    static public function getSearchTopicsFromParam($c, $parameters)
    {
        foreach($parameters as $k => $v){
            switch($k){
                case "resolve":
                    if($v){
                        $c->add(self::RESOLVE, $v);
                    }
                    break;
                case "member_id":
                    if($v){
                        $c->add(self::MEMBER_ID, $v);
                    }
                    break;
            }
        }
        return $c;
    }

}
